package cn.jyj.springframework.beans.factory.support;

import cn.jyj.springframework.beans.BeansException;
import cn.jyj.springframework.beans.factory.config.BeanDefinition;

/**
 * @Author 老顽固小可爱
 * @Date 2023/1/8 13:27
 * @Version 1.0
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {

    /*
    * 实现了 Bean 的实例化操作，在这里采用了 class.newInstance() 创建了无参构造函数，后面需要对有参构造函数重新定义
    * */
    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean = null;
        try {
            bean = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed", e);
        }

        addSingleton(beanName, bean);
        return bean;
    }

}
